package edu.njust.cma.controller;

import ch.qos.logback.core.joran.sanity.Pair;
import edu.njust.cma.pojo.Result;
import edu.njust.cma.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.AbstractMap;

@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    StandardService standardService;
    @Autowired
    QualityService qualityService;
    @Autowired
    ProjectService projectService;
    @Autowired
    SmallProjectService smallProjectService;

    @Autowired
    TaskService taskService;

    /**
     * 查看所有项目
     */
    @GetMapping("/getAll")
    public Result getAllProject() {
        return Result.success(projectService.getAllProject());
    }

    /**
     * 查看某个项目的所有小项目
     * */
    @GetMapping("/getSmallProject/{projectId}")
    public Result getSmallProject(@PathVariable Integer projectId) {
        return Result.success(smallProjectService.getSmallProject(projectId));
    }

    /**
     *  查看某个子项目的任务
     * */
    @GetMapping("/getTask/{smallProjectId}")
    public Result getTask(@PathVariable Integer smallProjectId) {
        return Result.success(taskService.getTask(smallProjectId));
    }

    /**
     *  获取某个项目的完成进度
     * */
    @GetMapping("/getCompletion/{id}")
    public Result getCompletion(@PathVariable Integer id){
        AbstractMap.SimpleEntry<Integer, Integer> ans = new AbstractMap.SimpleEntry<>(
                projectService.getCountTaskComplete(id),
                projectService.getCountTask(id)
        );
        return Result.success(ans);
    }

    /**
     *  查看某个任务的人员子任务
     * */
    @GetMapping("/getStaffTask/{taskId}")
    public Result getStaffTask(@PathVariable Integer taskId) {
        return Result.success(taskService.getStaffTask(taskId));
    }

    /**
     * 查看某个任务的设备子任务
     */
    @GetMapping("/getSubtaskEquipment/{taskId}")
    public Result getSubtaskEquipment(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskEquipment(taskId));
    }
    /**
     * 查看某个任务的样品子任务
     */
    @GetMapping("/getSubtaskSample/{taskId}")
    public Result getSubtaskSample(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskSample(taskId));
    }

    /**
     * 查看某个任务的额外要求子任务
     */
    @GetMapping("/getSubtaskAdditionalRequirement/{taskId}")
    public Result getSubtaskAdditionalRequirement(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskAdditionalRequirement(taskId));
    }

    @GetMapping("/getSubtaskAdditionalRequirementBySubTaskId/{subtaskId}")
    public Result getSubtaskAdditionalRequirementBySubTaskId(@PathVariable Integer subtaskId) {
        return Result.success(taskService.getSubtaskAdditionalRequirementBySubtaskId(subtaskId));
    }

    /**
     * 查看某个任务的设施子任务
     */
    @GetMapping("/getSubtaskFacility/{taskId}")
    public Result getSubtaskFacility(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskFacility(taskId));
    }

    /**
     * 查看某个任务的比对验证子任务
     */
    @GetMapping("/getSubtaskCompare/{taskId}")
    public Result getSubtaskComparison(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskComparison(taskId));
    }
    /**
     * 查看某个任务的检查子任务
     */
    @GetMapping("/getSubtaskInspect/{taskId}")
    public Result getSubtaskInspect(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskInspect(taskId));
    }

    /**
     * 查看某个任务的模拟实验子任务
     */
    @GetMapping("/getSubtaskSimulation/{taskId}")
    public Result getSubtaskSimulation(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskSimulation(taskId));
    }


}
